package com.headwind.logistics.carrier.controller;

import com.headwind.logistics.carrier.dto.CarAndCarTypeAndTansportUserDto;
import com.headwind.logistics.carrier.service.inter.CarAndCarTypeAndTansportUserServiceInter;
import com.headwind.logistics.common.pojo.*;
import com.headwind.logistics.common.util.LayuiUtil;
import com.headwind.logistics.common.util.RestResult;
import com.headwind.logistics.common.util.ResultCode;
import com.headwind.logistics.common.util.ResultGenerator;
import com.headwind.logistics.log.annotate.Log;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author QT
 * @Date 2020/7/17 16:06
 * @Version 1.0
 * @DESCRIPTION 司机车辆管理控制器层
 */
@Controller
public class CarAndCarTypeAndTansportUserController {
    //司机车辆管理业务逻辑层
    @Resource
    private CarAndCarTypeAndTansportUserServiceInter carAndCarTypeAndTansportUserServiceInter;

    //api统一响应格式
    @Resource
    private ResultGenerator resultGenerator;

    /**
     * 查询所有车的详情和运输人和模糊查询并分页
     * @param tansportName 模糊查询名字
     * @param page 页码
     * @param limit 行数
     * @return
     */
    @GetMapping("/admin/carrier/queryAllCarAndCarTypeAndTansportUser")
    @ResponseBody
    @Log("查询所有车的详情和运输人和模糊查询并分页")
    public LayuiUtil queryAllCarAndCarTypeAndTansportUser(String tansportName,Integer page,Integer limit){
        List<CarAndCarTypeAndTansportUserDto> list=carAndCarTypeAndTansportUserServiceInter.queryAllCarAndCarTypeAndTansportUser(tansportName,page,limit);
        return LayuiUtil.data(carAndCarTypeAndTansportUserServiceInter.queryAllCarAndCarTypeAndTansportUser(tansportName,null,null).size(),list);
    }

    /**
     * 修改运输人状态
     * @param transportuser 运输人对象
     * @return
     */
    @PostMapping("/admin/carrier/updateTransportUserStatus")
    @ResponseBody
    @Log("修改运输人状态")
    public RestResult updateTransportUserStatus(Transportuser transportuser){

        int count = 0;
        //修改用户
        count = carAndCarTypeAndTansportUserServiceInter.updateTransportUserStatus(transportuser);

        if (count >0){

            return resultGenerator.getSuccessResult("更改成功",count);

        }

        return resultGenerator.getFailResult("更改失败",count);
    }
    /**
     * 新增车、运输人、车辆登记信息
     * @param car 车对象
     * @param transportuser 运输人对象
     * @param carRegister 车辆登记对象
     * @param carid 车的id
     * @param transportuserid 运输人id
     * @return
     */
    @PostMapping("/admin/carrier/addCarAndTransportUserAndCarRegister")
    @ResponseBody
    @Log("新增车、运输人、车辆登记信息")
    public RestResult addCarAndTransportUserAndCarRegister(Car car, Transportuser transportuser, CarRegister carRegister,Long carid,Long transportuserid){
        int count = 0;
            //修改用户
            count = carAndCarTypeAndTansportUserServiceInter.addCarAndTransportUserAndCarRegister(car,transportuser,carRegister,carid,transportuserid);

        if (count > 0){
            return resultGenerator.getSuccessResult("新增成功",count);
        }


        return resultGenerator.getFailResult("新增失败",count);
    }
    /**
     * 查询所有车型
     * @return
     */
    @GetMapping("/admin/carrier/queryAllCarType")
    @ResponseBody
    @Log("查询所有车型")
    public List<Cartype> queryAllCarType(){
      List<Cartype>  list= carAndCarTypeAndTansportUserServiceInter.queryAllCarType();
        return  list;
    }
    /**
     * 查询所有员工
     * @return
     */
    @GetMapping("/admin/carrier/queryAllEmployee")
    @ResponseBody
    @Log("查询所有员工")
    public List<Employee> queryAllEmployee(){
        List<Employee>  list= carAndCarTypeAndTansportUserServiceInter.queryAllEmployee();
        return  list;
    }
}
